package org.webe.co.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.base.CharMatcher;
import com.google.common.base.Converter;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.primitives.Floats;
import com.google.common.primitives.Ints;

/**
 * Hello world!
 * 
 */
public class App {
	public static void main(String[] args) {
		// guava demo
		// null
		// Strings.isNullOrEmpty(null);
		// map
		Map<String, Map<Long, List<String>>> omap = new HashMap<String, Map<Long, List<String>>>();
		Map<String, Map<Long, List<String>>> nmap = Maps.newHashMap();
		// 不可变集合
		List<String> olist = new ArrayList<String>();
		olist.add("a");
		olist.add("b");
		olist.add("c");
		olist.add("d");
		ImmutableList<String> of = ImmutableList.of("a", "b", "c", "d");
		ImmutableMap<String, String> map = ImmutableMap.of("key1", "value1",
				"key2", "value2", "key3", "value3");
		// 文本文件读取现在Guava这么用
//		File file = new File(App.class.getClass().getResource("/test.txt").getFile());
//		List<String> lines = null;
//		try {
//			lines = Files.readLines(file, Charsets.UTF_8);
//		} catch (IOException e) {
//			e.printStackTrace(); 
//		}
		//基本类型比较, 现在Guava这么用
		int compare = Ints.compare(1, 3);  
		System.out.println(CharMatcher.DIGIT.retainFrom("some text 89983 and more"));  
		System.out.println(CharMatcher.DIGIT.removeFrom("some text 89983 and more"));
		int[] numbers = { 1, 2, 3, 4, 5 };  
		String numbersAsString = Joiner.on(";").join(Ints.asList(numbers));  
		System.out.println(numbersAsString);
		String numbersAsStringDirectly = Ints.join(";", numbers);  
		System.out.println(numbersAsStringDirectly);
		
		Iterable split = Splitter.on(";").split(numbersAsString);  
		
		String testString = "foo , what,,,more,";  
		Iterable<String> split2 = Splitter.on(";").omitEmptyStrings().trimResults().split(testString); 
		
		int[] array = { 1, 2, 3, 4, 5 };  
		int[] array2 = { 1, 2, 3, 4, 5 };  
		int a = 4;  
		boolean contains = Ints.contains(array, a);  
		int indexOf = Ints.indexOf(array, a);  
		int max = Ints.max(array);  
		int min = Ints.min(array);  
		int[] concat = Ints.concat(array, array2);  
		
		int count = -1;
		Preconditions.checkArgument(count > 0, "must be positive: %s", count);  
		
		
	}
}
